<?php
include 'constant.php';
include 'db_cred.php';

# Get Fullname and say Howdy!
$query = "select user_fullname from user where user_name = '". $_SESSION['authorized_user'] . "'";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$row = mysql_fetch_assoc($result);
printf ("Howdy, <A HREF=\"user_detail.php\">%s</A>!<BR />\n<BR />\n", $row["user_fullname"]);

# different operator in query for different type of request (past vs upcoming)
if ($_REQUEST['type'] == 'past')
{
  $op = '<';
  $upcoming_alerts = '<A HREF="?type=upcoming">Upcoming Events</A>';
  $past_alerts = 'Past Events';
}
else
{
  $op = '>=';
  $upcoming_alerts = 'Upcoming Events';
  $past_alerts = '<A HREF="?type=past">Past Events</A>';
}
$new_alert = '<A HREF="new_alert.php">New Event</A>';
print $upcoming_alerts . ' | ' . $past_alerts . ' | ' . $new_alert . "<BR>\n";
# get event summary SQL
$query = "select event_id, event_name, (event_dt + interval " . $_SESSION['user_timezone_offset'] . " hour) event_dt, event_is_muted from event where event_dt " . $op . " SYSDATE() and user_name = '" . $_SESSION['authorized_user'] . "' order by 3 asc";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
?>
<TABLE WIDTH=100% BORDER=1>
<TR><TH ALIGN=LEFT>Event Name</TH><TH ALIGN=LEFT>Date</TH></TR>
<?php
while ($row = mysql_fetch_assoc($result)) {
    # print table
    printf("<TR><TD><A HREF=\"alert_detail.php?event_id=%s\">%s</A></TD><TD>%s</TD></TR>\n",$row["event_id"],$row["event_name"],$row["event_dt"]);
}
?>
</TABLE>
<?php
// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>

